package org.jeecg.modules.controller;

import java.util.Arrays;
import java.util.List;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.dto.PlatformManagementDto;
import org.jeecg.modules.entity.CuPlatformManagement;
import org.jeecg.modules.service.ICuPlatformManagementService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;

/**
 * @Description: 平台列表
 * @Author: jeecg-boot
 * @Date: 2024-07-12
 * @Version: V1.0
 */
@Tag(name = "平台列表")
@RestController
@RequestMapping("/cuckoo/cuPlatformManagement")
@Slf4j
public class CuPlatformManagementController extends JeecgController<CuPlatformManagement, ICuPlatformManagementService> {
    @Autowired
    private ICuPlatformManagementService cuPlatformManagementService;

    /**
     * 分页列表查询
     *
     * @param cuPlatformManagement
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @Operation(summary = "平台列表-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<CuPlatformManagement>> queryPageList(CuPlatformManagement cuPlatformManagement,
                                                             @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                             HttpServletRequest req) {
        QueryWrapper<CuPlatformManagement> queryWrapper = QueryGenerator.initQueryWrapper(cuPlatformManagement, req.getParameterMap());
        Page<CuPlatformManagement> page = new Page<CuPlatformManagement>(pageNo, pageSize);
        IPage<CuPlatformManagement> pageList = cuPlatformManagementService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    @Operation(summary = "平台列表-缓存")
    @GetMapping(value = "/listAll")
    public Result<List<PlatformManagementDto>> listAll(HttpServletRequest req) {
        List<PlatformManagementDto> list = cuPlatformManagementService.PlatformlistAll();
        return Result.OK(list);
    }

    /**
     * 添加
     *
     * @param cuPlatformManagement
     * @return
     */
    @AutoLog(value = "平台列表-添加")
    @Operation(summary = "平台列表-添加")
    @RequiresPermissions("cuckoo:cu_platform_management:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody CuPlatformManagement cuPlatformManagement) {
        cuPlatformManagementService.save(cuPlatformManagement);
        return Result.OK("添加成功！");
    }

    /**
     * 编辑
     *
     * @param cuPlatformManagement
     * @return
     */
    @AutoLog(value = "平台列表-编辑")
    @Operation(summary = "平台列表-编辑")
    @RequiresPermissions("cuckoo:cu_platform_management:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody CuPlatformManagement cuPlatformManagement) {
        cuPlatformManagementService.updateById(cuPlatformManagement);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "平台列表-通过id删除")
    @Operation(summary = "平台列表-通过id删除")
    @RequiresPermissions("cuckoo:cu_platform_management:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        cuPlatformManagementService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "平台列表-批量删除")
    @Operation(summary = "平台列表-批量删除")
    @RequiresPermissions("cuckoo:cu_platform_management:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.cuPlatformManagementService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "平台列表-通过id查询")
    @Operation(summary = "平台列表-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<CuPlatformManagement> queryById(@RequestParam(name = "id", required = true) String id) {
        CuPlatformManagement cuPlatformManagement = cuPlatformManagementService.getById(id);
        if (cuPlatformManagement == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(cuPlatformManagement);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param cuPlatformManagement
     */
    @RequiresPermissions("cuckoo:cu_platform_management:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, CuPlatformManagement cuPlatformManagement) {
        return super.exportXls(request, cuPlatformManagement, CuPlatformManagement.class, "平台列表");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    @RequiresPermissions("cuckoo:cu_platform_management:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, CuPlatformManagement.class);
    }

}
